home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / PublicDomain / Anwendungen / DMAmon / DMAmon.text < prev    next >
Text File  |  1999-10-26  |  6KB  |  123 lines

  1. DMAmon by Simon N Goodwin
  2.  
  3. DMAmon indicates in a Workbench window when Amiga disk drives 
  4. and sound channels are in use. Source code in HiSoft BASIC is 
  5. included.
  6.  
  7. This program is an expanded version of a utility written by 
  8. Simon N Goodwin for the current Amiga Format magazine tutorial 
  9. series 'Banging The Metal'. This special version for Aminet is 
  10. published under the author's agreement with Future Publishing, 
  11. which allows non-exclusive distribution of material written for 
  12. the magazine, six months after publication. It is hoped that 
  13. other examples and tutorials wil lbe made more widely available 
  14. this way. You can already read an extended version of the Amiga 
  15. Format Emulation series on the web, thanks to Simon  Goodwin and 
  16. Thomas Amsrud, who translated the original to HTML. To read 
  17. this, go to:
  18.  
  19.         http://www.emulnews.com/aer/articles/af/
  20.  
  21. The example program
  22.  
  23. DMAmon uses HiSoft BASIC to monitor disk and audio memory 
  24. access. It works by checking the DMACONR and DSKBYTR registers 
  25. at regular intervals.The only explicit system call is to Delay, 
  26. in the DOS library, linked by the first couple of lines. This 
  27. prevents the program hogging the CPU, updating faster than the 
  28. eye can see, by periodically surrendering time to other tasks.
  29.  
  30. The value after Delay, near the end, counts display fields 
  31. before the loop repeats. Press Control C to stop the task. On my 
  32. PAL A4000 Delay &20 permits updates two or three times per 
  33. second, draining less than 1.5 per cent of the CPU time. Delay 
  34. &10 updates twice as fast, six times per second on NTSC 
  35. displays, and so on. Alternatively you might give the program a 
  36. negative priority, so it defers to foreground tasks.
  37.  
  38. Scattered &s indicate HiSoft BASIC long word values, versus % 
  39. for 16 bit integers. &H preceeds hex values (like $ in assembler 
  40. or 0x in C) such as the custom register base, &hDFF000, and &B 
  41. denotes binary.
  42.  
  43. Disk DMA
  44.  
  45. The floppy disk DMA channel can read or write data to up to four 
  46. drives. The second and third most significant bits in DSKBYTR 
  47. show when this is happening. The second (bit 14, masked out with 
  48. binary in the listing) is set while disk DMA is is progress. The 
  49. third (bit 13) is set during floppy writes.
  50.  
  51. This helps reveal why your drives are grinding away. Some 
  52. programs leave the drive motors running when there's no DMA, so 
  53. disks can safely be removed. Beware of removing a disk even when 
  54. apparently just reading; the system may switch to writing before 
  55. your finger reaches the eject button. You'll soon learn when 
  56. this is likely, with DMAmon as your guide.
  57.  
  58. Sound DMA
  59.  
  60. It's similarly useful to monitor active sound channels. Sound 
  61. channels are a scarce resource and should be shared. Some 
  62. applications require channels, and a few nasty ones hog them, 
  63. even when not in use. DMAmon shows the status of each of the 
  64. four channels dynamically, with 0 for a free channel and 1 if 
  65. the channel is in use.
  66.  
  67. You could recode this to use graphics or left/right grouping 
  68. rather than hardware chanel order. I've done it the obvious way 
  69. for BASIC, extracting four adjacent bits with AND then 
  70. converting to binary with BIN$. The prefix "000" and RIGHT$(,4) 
  71. make leading zeros explicit.
  72.  
  73. Typically, Amiga registers combine several functions, assigning 
  74. distinct control to each bit. Each one or zero bit indicates a 
  75. distinct state in the underlying hardware. The table lists the 
  76. significance of bits in DMACONR and DSKBYTR.
  77.  
  78. DMACONR is a read-only version of DMACON. Like other crucial 
  79. controls, the 'top' (most significant) bit indicates setting or 
  80. clearing of other bits - so a single write with one bit set 
  81. CLEARs just that bit! If the top bit and others are set, those 
  82. are added to the ones already set. This brilliance saves 
  83. reading, masking and writing values back, and eases Copper 
  84. programming.
  85.  
  86. These are readily accessible, but not the only DMA control bits. 
  87. BPLCON ($DFF100) determines the number of bitplanes in use. 
  88. There's no BPLCONR so you must record changes. DMAmon does not 
  89. monitor bitplane DMA as it's static for a given display mode, 
  90. and you won't see anything if it's turned off! Sprite DMA could 
  91. be monitored but most programs disable sprites by changing to a 
  92. small transparent pattern or parking them in the border, rather 
  93. than stopping their DMA.
  94.  
  95. The Copper is constantly active, but usually only gains priority 
  96. over the CPU for a few microseconds at a time. It would be 
  97. interesting to monitor Blitter activity, but difficult in Amiga 
  98. OS windows; the system uses blits to update them, so you can't 
  99. report the Blitter's status unless it is idle! 
  100.  
  101. Simon N Goodwin, Oldbury, March 1999, Aminet Update October 1999
  102.  
  103. Table: Sample DMA register bit assignments
  104.  
  105. Bit             DMACON                  DSKBYTR
  106.  
  107. 15              Set/Clear               Data Valid
  108. 14              Blitter Busy            DMA active
  109. 13              Blitter Zero            Disk writing
  110. 12              Unassigned              Sync match
  111. 11              Unassigned              Unassigned
  112. 10              Blitter Nasty           Unassigned
  113.  9              Master DMA              Unassigned
  114.  8              Bitplane DMA            Unassigned
  115.  7              Copper DMA              Data bit 7
  116.  6              Blitter DMA             Data bit 6
  117.  5              Sprite DMA              Data bit 5
  118.  4              Floppy DMA              Data bit 4
  119.  3              Right audio 2           Data bit 3
  120.  2              Left audio 2            Data bit 2
  121.  1              Left audio 1            Data bit 1
  122.  0              Right audio 1           Data bit 0
  123.